package com.dreamcode.caloriestracker.utils;

import java.util.LinkedList;
import java.util.List;

import com.dreamcode.caloriestracker.modelclass.CalculationDetails;

public class CalorieUtils {	
	public static String [] sports={"Aerobics(low impact)", "Aerobics(high impact)", "Aerobics Step(low impact)", "Aerobics Step(high impact)", "Aerobics(water)",
			"Bicycling(stacionary moderate)", "Bicycling(stacionary vigorous)", "Circuit Training(general)", "Rowing(stacionary moderate)", 
			"Rowing(stacionary vigorous)", "Ski Machine(general)", "Stair Step Machine(general)", "Weight Lifting(general)", "Weight Lifting(vigorous)",
			"Basketball(playing a game)", "Basketball(wheelchair)", "Bicycling(BMX or mountain)", "Bicycling(12-13.9 mph)", "Bicycling(14-15.9 mph)",
			"Boxing: sparring", "Football(competitive)", "Football(touch, flag, general)", "Frisbee", "Golf(carrying clubs)", "Golf(using cart)",
			"Gymnastics(general)", "Handball(general)", "Hiking(cross-country)", "Horseback Riding(general)", "Ice Skating(general)",
			"Martial Arts(general)", "Racquetball(competitive)", "Racquetball(casual, general)", "Rock Climbing(ascending)", "Rock Climbing(repelling)",
			"Rollerblade Skating", "Rope Jumping", "Running(5 mph (12 min/mile))", "Running(5.2 mph (11.5 min/mile))", "Running(6 mph (10 min/mile))",
			"Running(6.7 mph (9 min/mile))", "Running(7.5 mph (8 min/mile))", "Running(8.6 mph (7 min/mile))", "Running(10 mph (6 min/mile))",
			"Running(pushing wheelchair, marathon wheeling)", "Running(cross-country)", "Skiing(cross-country)", "Skiing(downhill)", "Snow Shoeing",
			"Softball(general play)", "Swimming(general)", "Tennis(general)", "Volleyball(non-competitive,general play)", "Volleyball(competitive, gymnasium play)",
			"Volleyball(beach)", "Walk(3.5 mph (17 min/mi))", "Walk9(4 mph (15 min/mi))", "Walk(4.5 mph (13 min/mi))", "Walk/Jog(jog <10 min.)", "Water Skiing",
			"Water Polo", "Whitewater(rafting, kayaking)", "Chopping & Splitting Wood", "Gardening(general)", "Housecleaning(general)", "Mowing Lawn(push, hand)",
			"Mowing Lawn(push, power)", "Operate Snow Blower(walking)", "Children's Games(4-square, etc.)", "Raking Lawn", "Sex(moderate effort)","Shoveling Snow(by hand)"};
		
	
	public static String[] getSports() {
		return sports;
	}

	public static void setSports(String[] sports) {
		CalorieUtils.sports = sports;
	}

	public static double[] getSportsFactors() {
		return sportsFactors;
	}

	public static void setSportsFactors(double[] sportsFactors) {
		CalorieUtils.sportsFactors = sportsFactors;
	}

	private static double [] sportsFactors={0.044,0.056,0.056,0.080,0.032,0.056,0.084,0.064,0.056,0.068,0.076,0.048,0.024,0.048,0.064,0.052,0.068,0.064,0.080,0.072,0.072,0.064,
			0.024,0.044,0.028,0.032,0.096,0.048,0.032,0.056,0.080,0.080,0.056,0.088,0.064,0.056,0.080,0.064,0.072,0.080,0.088,0.100,0.116,0.132,0.064,0.072,0.064,
			0.048,0.064,0.040,0.048,0.056,0.024,0.032,0.064,0.032,0.036,0.040,0.048,0.048,0.080,0.040,0.048,0.036,0.028,0.044,0.036,0.036,0.040,0.032,0.012,0.048};
	
	public static String calculateCaloriesByTime(int id, int w, int min){
		return  String.valueOf(Math.round(w*min*sportsFactors[id]));
	}
	
	public static String calculateCaloriesByTime(int id, double w, double min){
		return  String.valueOf(Math.round(w*min*sportsFactors[id]));
	}
	
	public static String calculateTimeByCalories(int id, int w, int cal){
		return  String.valueOf(Math.round(cal/(w*sportsFactors[id])));
	}
	
	public static String calculateTimeByCalories(int id, double w, double cal){
		return  String.valueOf(Math.round(cal/(w*sportsFactors[id])));
	}
	
	public static CalculationDetails calculateProfileData(int age, boolean sexFlag, double w, double h, double wa){
		CalculationDetails calculationDetails = new CalculationDetails();
		List<Long>recommendedWeightList = new LinkedList<Long>();
		
		double ibwevalue = 0;
		if(age>17){			
			recommendedWeightList.add(Math.round((19 * Math.pow((h/100),2))));
			recommendedWeightList.add(Math.round((25 * Math.pow((h/100),2))));			
			ibwevalue = Math.round((Math.round((19 * Math.pow((h/100),2))) + Math.round((25 * Math.pow((h/100),2))))/2);
			
		}else{
			recommendedWeightList.add(null);
			recommendedWeightList.add(null);
		}		
		calculationDetails.setBodyMassIndex(Math.round(MathBodyComp.CalcBMI((h/100), w)));
		calculationDetails.setWaistToHeightRatio(Math.round((wa*100)/h));
		//calculationDetails.setBodyFat(Math.round((100*(MathBodyComp.CalcBodyFatYmcaWeight(w, wa / 100.0D, true, sexFlag)))/w));
		calculationDetails.setBodyFat(Math.round((100*((sexFlag==true?-98.42:-76.76) + 4.15*(wa/2.54) - 0.082*(w*2.2))/(w*2.2))));
		calculationDetails.setSurfaceArea(Math.round(Math.sqrt(((h*w))/3600)));
		calculationDetails.setBasalMetabolicRate(Math.round((sexFlag==true?66:655) + ((sexFlag==true?13.7:9.6) * w ) + ((sexFlag==true?5:1.8) * h) - ((sexFlag==true?6.8:4.7) * age)));
		calculationDetails.setIdealBodyWeight(ibwevalue);
		calculationDetails.setRecommendedBodyWeight(recommendedWeightList);
		calculationDetails.setLeanBodyMassIndex(Math.round(((sexFlag==true?1.1:1.07) * w) - (((sexFlag==true?128:148) * Math.pow(w,2))/Math.pow(h, 2))));
		
		return calculationDetails;		
	}
		
	
}
